/**
* project3D Engine
* @author John Sword
* @version 2 - AS3
* 
* simple Plane Primitive
*/

package engine.objects
{
	
	import engine.geom.UV;
	import engine.geom.Vector;
	import engine.geom.Vertex;
	import engine.materials.Material;

	public class Plane extends Object3D
	{
		
		private var h:Number;
		private var w:Number;
		
		/**
		* Constructor
		* @param d Depth of the Plane
		* @param w Width of the Plane
		* @param r Render mode
		*/
		public function Plane ( m:Material, w:int, h:int )
		{
			this.h = (!w) ? 10 : w;
			this.w = (!h) ? 10 : h;
			this.position = new Vector();
			this.material = m;
			this.cull = false;
			build();
			
		}
		
		// initialization
		private function build () : void
		{
			// build vertexes
			createVertex(new Vertex (-w,-h,0));
			createVertex(new Vertex (w,-h,0));
			createVertex(new Vertex (-w,h,0));
			createVertex(new Vertex (w,h,0));
			
			createFace ( 2, 0, 1, new UV(1,0),new UV(1,1),new UV(0,1), material );
			createFace ( 1, 3, 2, new UV(0,1),new UV(0,0),new UV(1,0), material );
			
			// build faces (a Tri Poly box has 12 faces)
			//createFaceVertexCoords(0,2,3);
			//createFaceVertexCoords(3,1,0);
			
			// texture coordinates
			//createUV(0,2,3,[[1,0],[1,1],[0,1]]);
			//createUV(3,1,0,[[0,1],[0,0],[1,0]]);
			/*
			var i:Number = aFacesAssoVertex.length;
			while (i--)
			{
				var v1:Number = int(aFacesAssoVertex[i][0]);
				var v2:Number = int(aFacesAssoVertex[i][1]);
				var v3:Number = int(aFacesAssoVertex[i][2]);
				// for retrieving texture uvs from textures array
				var texVs:String = v1+","+v2+","+v3; // 3 vertices form a face
				// get uv coords for this face
				var texsUVs:Array = aFacesTextures[texVs];
				var a:Vertex = tVertices[aFacesAssoVertex[i][0]];
				var b:Vertex = tVertices[aFacesAssoVertex[i][1]];
				var c:Vertex = tVertices[aFacesAssoVertex[i][2]];
				//faces.push( new Face ( [ a, b, c ], material, texsUVs ) );
			}
			
			transform_vertices ( null );
			*/
		}
	}

	
}

